﻿<%@ WebHandler Language="C#" Class="GetShowImgHandler" %>

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Business.Common;
using Business.Model;
using WF_Business;

public class GetShowImgHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        var type = context.Request["type"];
        context.Response.ContentType = "text/plain";
        context.Response.Write(GetJsonData(type));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    private string GetJsonData(string type)
    {
        var dtTemp = GetData(type);
        var list = new List<NewsInfo>();
        dtTemp.Rows.Cast<DataRow>().ToList().ForEach(row =>
        {
            list.Add(new NewsInfo
            {
                Id = row["Id"].ToString(),
                Title = row["bt"].ToString(),
                ShowImage = row["showimg"].ToString(),
                ShowNo = Convert.ToInt32(row["showno"]),
            });
        });
        return list.T2Json();
    }

    private DataTable GetData(string type)
    {
        DataTable dtTemp;
        var strSql = string.Format("select Id,bt,showimg,(rownum-1) showno from (select * from ut_XWFB where fbzt=1 and LX ='{0}' order by iid desc ) where rownum<=4 ", type);
        SysParams.OAConnection().RunSql(strSql, out dtTemp);
        return dtTemp;
    }
}